<template>
	<div class="loading">
	</div>
</template>

<script>
// 引入这个页面需要的方法库
import axios from 'axios'
import {getToken} from 'api/api'
import {mapMutations} from 'vuex'
/* eslint-disable */
export default {
  mounted () {
    // 在loading页面获取公共Token，
    // 如果公共Token不为空则跳转到登陆页
    axios.get(getToken, {
      params: {
        client_secret: 'cmPUgWgqFI8',
        grant_type: 'password',
        scope: 'pub_api,biz_api,acc_api',
        username: '15071496803',
        password: 'dsq7170490',
        client_id: 'wc-client'
      }
    }).then((res) => {
      console.log(res.data)
      localStorage.setItem('token', res.data.access_token)
      if (res.data.access_token !== '' && res.data.access_token !== undefined) {
        let pub = res.data.access_token
        this.setPublicToken(pub)
        this.$router.push('/index')
      }
    }).catch(error => {
      console.log(error)
    })
  },
  methods: {
    ...mapMutations({
      setPublicToken: 'SET_PUBLICTOKEN'
    })
  }
}
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  .loading
    width: 100%
    height: 100vh
</style>